<?php

namespace App\Http\Controllers\Admin;

use App\Coupon;
use App\Http\Response;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Ramsey\Uuid\Uuid;

class CouponController extends Controller
{
    use Response;

    public function index(Request $request)
    {
        $paginate=Coupon::paginate($request->get('pageSize'),'*','pageNo');
        return $this->success(200,$paginate);
    }
    public function store(Request $request)
    {
       $data=$request->all();
       $data['bind_goods']=[];
       $create=Coupon::create($data);
       if ($create){
           return $this->message(200,'创建成功');
       }else{
           return $this->error(505,'创建失败');
       }
    }
    public function show($id)
    {
        $data=Coupon::find($id);
        return $this->success(200,$data);
    }
    public function update($id,Request $request)
    {
        $update=Coupon::where('id',$id)->update($request->all());
        if ($update){
            return $this->message(200,'更新成功');
        }else{
            return $this->error(505,'更新失败');
        }
    }
    public function destroy($id)
    {
        Coupon::destroy($id);
        return $this->message(200,'删除成功');

    }
}
